Skip to content

fix(task-create): handle WorkflowAlreadyStartedError gracefully - #489

Open
alvinkam2001 wants to merge 1 commit into
nextfrom
akam/task-create-idempotency
Open

fix(task-create): handle WorkflowAlreadyStartedError gracefully#489
alvinkam2001 wants to merge 1 commit into
nextfrom
akam/task-create-idempotency

Conversation

@alvinkam2001

@alvinkam2001 alvinkam2001 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Makes task/create idempotent in the Temporal ACP path. Duplicate submits for the same task ID (e.g. load-balanced agentex-agent replicas racing on the same notification) no longer surface WorkflowAlreadyStartedError, Temporal returns the existing workflow handle instead.

Change

  • TemporalTaskService.submit_task now passes id_conflict_policy=WorkflowIDConflictPolicy.USE_EXISTING.
  • TemporalClient.start_workflow accepts an id_conflict_policy param (defaults to UNSPECIFIED, preserving current behavior for any other caller).

Why

WorkflowIDReusePolicy.ALLOW_DUPLICATE (already set) only governs reuse after a run closes — it doesn't help when a run is currently open. Workflows are mainly just noise as the workflow still runs

Test plan

  • New unit tests in tests/lib/core/services/test_temporal_task_service.py:
    • submit_task passes USE_EXISTING to the client
    • TemporalClient.start_workflow forwards id_conflict_policy when set
    • TemporalClient.start_workflow defaults to UNSPECIFIED (backwards-compat)
  • Existing TemporalTaskService tests still pass
  • Sanity check in staging: fire two task/create calls with the same task ID, confirm both return 200 with the same workflow ID and no error log

Greptile Summary

The PR makes Temporal-backed task creation idempotent while a workflow with the same task ID remains open.

  • Adds conflict-policy forwarding to the Temporal client wrapper while preserving the existing default.
  • Uses USE_EXISTING when submitting tasks.
  • Adds focused tests for service configuration, forwarding, and default behavior.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
src/agentex/lib/core/clients/temporal/temporal_client.py Adds a backward-compatible workflow ID conflict-policy parameter and forwards it to Temporal.
src/agentex/lib/core/temporal/services/temporal_task_service.py Configures task workflow starts to reuse the active execution when the task ID conflicts.
tests/lib/core/services/test_temporal_task_service.py Adds unit coverage for the task service policy and Temporal client forwarding and default behavior.

Reviews (2): Last reviewed commit: "handle same workflow task/create gracefu..." | Re-trigger Greptile

@alvinkam2001
alvinkam2001 force-pushed the akam/task-create-idempotency branch from dbfcca6 to 58c27ea Compare August 7, 2026 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant